package com.mysafe.provision.service;

import javax.inject.Inject;

import com.mysafe.provision.exception.ValidationException;
import com.mysafe.provision.persistence.IDAO;


public abstract class PersistenceService<T> implements IPersistableEntity<T> {

	private IDAO<T> dao;
	
	@Inject
	public PersistenceService(IDAO<T> dao) {
		this.dao = dao;
	}

	@Override
	public void insert(T entity) throws ValidationException {
		validateInsert(entity);
		dao.persist(entity);
	}

	@Override
	public void update(T entity) throws ValidationException {
		validateUpdate(entity);
		dao.merge(entity);
	}

	@Override
	public boolean canDelete(T entity) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public void delete(T entity) {
		// TODO Auto-generated method stub
		
	}

}
